package com.fatri.lessionsimple.opengl

import android.content.Context
import android.opengl.GLES20
import android.opengl.GLUtils
import android.util.Log

abstract class IDrawer(val ctx: Context) {

    abstract fun onSurfaceCreated()
    abstract fun onSurfaceChanged(width: Int, height: Int)
    abstract fun onDrawFrame()
    abstract fun release()


    fun loadShader(type: Int, code: String): Int {
        val shader = GLES20.glCreateShader(type)
        GLES20.glShaderSource(shader, code)
        GLES20.glCompileShader(shader)
        return shader
    }

    fun traceError() {
        var error: Int
        while (GLES20.glGetError().also { error = it } != GLES20.GL_NO_ERROR) {
            val errStr = GLUtils.getEGLErrorString(error)
            Log.e("CZB", "errorCode=${error},msg=${errStr}")
        }

    }
}